import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
import {Response,Request} from 'express'
@Catch(HttpException)
export class ErrorfilterFilter implements ExceptionFilter {
  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp()
    const req = ctx.getRequest<Request>()
    const res = ctx.getResponse<Response>()
    const status = exception.getStatus()

    // const msg = exception.message;
    // 如果你放入的是对象的话  这样才会正常的显示
    const msg = exception.getResponse();
    res.status(status).json({
      error:1,
      msg,
      status,
      time: new Date().getTime()
    })
  }
}
